/**
 * <p>Copyright:Copyright(c) 2019</p>
 * <p>Company:Professional</p>
 * <p>Package:org.cesgroup.course.autoconfigure</p>
 * <p>File:Ch003AutoConfiguration.java</p>
 * <p>类更新历史信息</p>
 * @todo chanlong(陈龙) 创建于 Sep 12, 2019 12:50:35 PM
 */
package org.cesgroup.course.autoconfigure;

import org.cesgroup.course.converter.Converter;
import org.cesgroup.course.converter.SimpleConverter;
import org.cesgroup.course.interceptor.Interceptor;
import org.cesgroup.course.interceptor.ProxyChain;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <p>描述: </p>
 * <p>Company: Professional</p>
 * @author chanlong(陈龙)
 * @date Sep 12, 2019 12:50:35 PM
 * @version 1.0.2019
 */
@Configuration
@ConfigurationProperties(prefix = "ces.resources")
public class Ch003AutoConfiguration {

	private final Interceptor[] interceptors;
	private final ProxyChain<Converter> proxyChain = new ProxyChain<>();

	// 项目启动时，向“代理责任链”添加“Interceptor”实例
	public Ch003AutoConfiguration(ObjectProvider<Interceptor[]> provider) {
		this.interceptors = provider.getIfAvailable();
		for (Interceptor interceptor : interceptors) {
			proxyChain.addInterceptor(interceptor);
		}
	}

	// 加载所有代理对象，设置目标对象，创建目标对象的bean
	@Bean
	public Converter converter() {
		return proxyChain.all(new SimpleConverter());
	}

	private String staticLocation;

	public String getStaticLocation() {
		return staticLocation;
	}

	public void setStaticLocation(String staticLocation) {
		this.staticLocation = staticLocation;
	}
	
}
